import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      crypto: 'crypto-browserify',
    },
  },
  server: {
    host: "0.0.0.0", // 允许所有地址访问
    port: 5173,
    proxy: {
      '/api': {
        target: 'http://172.16.80.20:8080/cupk2/',  // Spring Boot 后端地址
        changeOrigin: true,  // 改变请求头中的 Origin 字段
        rewrite: (path) => path.replace(/^\/api/, '')  // 将请求路径的 /api 部分去掉
      }
    }
  },
});
